********************************************************************************
********************************************************************************

// Import quantification of the plans of action

import excel "$Intervention_dtDeID/plans_of_action.xlsx", sheet("Sheet1") firstrow clear

save "$Intervention_dtInt/PoA.dta", replace

********************************************************************************
********************************************************************************

// Import participation in door-to-door visits and school meetings

import excel "$Intervention_dtDeID/interventiondata.xlsx", sheet("door") firstrow clear

save "$Intervention_dtInt/participation.dta", replace

reshape long date parents repeats mdate meeting super duration, i(school_id) j(round)

replace repeats=0 if round==1 & repeats!=.
gen newparents = parents - repeats

sort school_id

by school_id: egen unique = sum(newparents)

gen completed = 0 if inlist(treatment,2,3)
replace completed = 1 if mdate!=.

********************************************************************************
********************************************************************************

// Combine intervention datasets

merge 1:1 school_id round using "$Intervention_dtInt/PoA.dta"

drop _merge

********************************************************************************
********************************************************************************

// Transform variables into dummies

gen acom = acompanylearning
replace acom = acomschool if acom == .
replace acom = 1 if work ==1

foreach var in work contribution accountability parcom acom acompanylearning 		///
acomschool owncampaign security higiene cleaning cleanperson secureperson 		///
general_improvements door_window bathroom fence garden electricity water desks 	///
trashcans board notebooks food extra transport_homeschool teacherbehavior 		///
teacher_conditions transport_teachers											///
{
replace `var' = 1 if `var' != .
replace `var' = 0 if `var' == . & completed==1
}

********************************************************************************
********************************************************************************

// Create general indicators for higiene and safety

*higiene cleaning cleanperson bathroom water trashcans

egen higiene2 = rowtotal(cleaning cleanperson bathroom water trashcans)
replace higiene = 1 if higiene2>0

********************************************************************************

* safety security secureperson door_window fence transport_homeschool

egen safety2 = rowtotal(secureperson door_window fence transport_homeschool)
gen safety = 0
replace safety = 1 if safety2>0

********************************************************************************

drop transport_teachers higiene2 safety2 security

********************************************************************************
********************************************************************************

preserve

use school_id students regschool t if regschool==1 & t==0 using "$Endline_dtFin/data_angolacbm.dta", clear

drop t regschool

save "$Intervention_dtInt/school_size.dta", replace

restore

merge m:1 school_id using "$Intervention_dtInt/school_size.dta"

drop if _merge==2

drop _merge

// Coverage

foreach var in parents meeting newparents{
gen `var'_cov = `var'/students
}

gen coverage_dtd = unique/students
replace coverage_dtd = . if inlist(treatment,0,2)


********************************************************************************
********************************************************************************

// Make non applicable entries 0 for graph purposes.

replace parents = 0 if treatment==2
replace parents_cov = 0 if treatment==2

replace newparents = 0 if treatment==2
replace newparents_cov = 0 if treatment==2

replace meeting = 0 if treatment==1
replace meeting_cov = 0 if treatment==1

replace duration = 0 if treatment==1

********************************************************************************
********************************************************************************



save "$Intervention_dtFin/data_interventions", replace
